package com.ruoyi.project.jiaqin.wanttobuy.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.wanttobuy.domain.WantToBuy;
import com.ruoyi.project.jiaqin.wanttobuy.service.IWantToBuyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 采购Controller
 * 
 * @author admin
 * @date 2020-12-25
 */
@Controller
@RequestMapping("/jiaqin/wanttobuy")
public class WantToBuyController extends BaseController
{
    private String prefix = "jiaqin/wanttobuy";

    @Autowired
    private IWantToBuyService wantToBuyService;

    @RequiresPermissions("jiaqin:wanttobuy:view")
    @GetMapping()
    public String wanttobuy()
    {
        return prefix + "/wanttobuy";
    }

    /**
     * 查询采购列表
     */
    @RequiresPermissions("jiaqin:wanttobuy:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WantToBuy wantToBuy)
    {
        startPage();
        List<WantToBuy> list = wantToBuyService.selectWantToBuyList(wantToBuy);
        return getDataTable(list);
    }

    /**
     * 导出采购列表
     */
    @RequiresPermissions("jiaqin:wanttobuy:export")
    @Log(title = "采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WantToBuy wantToBuy)
    {
        List<WantToBuy> list = wantToBuyService.selectWantToBuyList(wantToBuy);
        ExcelUtil<WantToBuy> util = new ExcelUtil<WantToBuy>(WantToBuy.class);
        return util.exportExcel(list, "wanttobuy");
    }

    /**
     * 新增采购
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购
     */
    @RequiresPermissions("jiaqin:wanttobuy:add")
    @Log(title = "采购", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WantToBuy wantToBuy)
    {
        return toAjax(wantToBuyService.insertWantToBuy(wantToBuy));
    }

    /**
     * 修改采购
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WantToBuy wantToBuy = wantToBuyService.selectWantToBuyById(id);
        mmap.put("wantToBuy", wantToBuy);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购
     */
    @RequiresPermissions("jiaqin:wanttobuy:edit")
    @Log(title = "采购", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WantToBuy wantToBuy)
    {
        return toAjax(wantToBuyService.updateWantToBuy(wantToBuy));
    }

    /**
     * 删除采购
     */
    @RequiresPermissions("jiaqin:wanttobuy:remove")
    @Log(title = "采购", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wantToBuyService.deleteWantToBuyByIds(ids));
    }
}
